<?php
    $iniVars = parse_ini_file('../config.ini',TRUE);
    include('../classes/adodb5/adodb.inc.php');
    include('db.tl.func.php');
    include('../classes/class.upload.php');
?>
    <script type="text/javascript" src="../js/jquery.js"></script>
    <script type="text/javascript" src="../js/jqueryui.js"></script>
    <link type="text/css" href="../css/jquryui_flick/style.css" rel="stylesheet" />
<?php
    
    $frm_no = $_POST['frm_no'];
    
    if($frm_no==1)
    {
        
        $personal_title = $_POST['personal_title_r'];
        if($personal_title=='etctitle')
        {
            $personal_title = $_POST['personal_title_r'];
        }
        
        $personal_firstname_th = $_POST['personal_firstname_th'];
        $personal_lastname_th = $_POST['personal_lastname_th'];
        $personal_nickname_th = $_POST['personal_nickname_th'];
        $personal_firstname_en = $_POST['personal_firstname_en'];
        $personal_lastname_en = $_POST['personal_lastname_en'];
        $personal_nickname_en = $_POST['personal_nickname_en'];
        
        $personal_birth = explode('/',$_POST['personal_birth']);
        $personal_birth_r = date("Y-m-d H:i:s",mktime(0, 0, 0, $personal_birth[1], $personal_birth[0], $personal_birth[2]));
        
        $personal_id_no = $_POST['personal_id_no'];
        //$personal_photo = $_FILES['personal_photo'];//88888888888888888888888
        $personal_email = $_POST['personal_email'];
        $personal_homephone = $_POST['personal_homephone'];
        $personal_mphone_1 = $_POST['personal_mphone_1'];
        $personal_mphone_network_1 = $_POST['personal_mphone_network_1'];
        $personal_mphone_2 = $_POST['personal_mphone_2'];
        $personal_mphone_network_2 = $_POST['personal_mphone_network_2'];
        $personal_room_no = $_POST['personal_room_no'];
        $personal_home_no = $_POST['personal_home_no'];
        $personal_village_name = $_POST['personal_village_name'];
        $personal_mhu = $_POST['personal_mhu'];
        $personal_soi = $_POST['personal_soi'];
        $personal_road = $_POST['personal_road'];
        $personal_subdistrict = $_POST['personal_subdistrict'];
        $personal_district = $_POST['personal_district'];
        $personal_province = $_POST['personal_province'];
        $personal_postal_code = $_POST['personal_postal_code'];
        
        $sql = <<<sql
            INSERT INTO tutor (title,first_name_th,last_name_th,nick_name,first_name_en,last_name_en,birthday,citizen_id,email,telephone_home,mobile01,mobile01_network,mobile02,mobile02_network,add_room_no,add_home_no,add_building_name,add_moo,add_soi,add_road,add_distinct,add_area,add_province,add_post_code,source,is_active,create_date) VALUES('{$personal_title}','{$personal_firstname_th}','{$personal_lastname_th}','{$personal_nickname_en}','{$personal_firstname_en}','{$personal_lastname_en}','{$personal_birth_r}','{$personal_id_no}','{$personal_email}','{$personal_homephone}','{$personal_mphone_1}','{$personal_mphone_network_1}','{$personal_mphone_2}','{$personal_mphone_network_2}','{$personal_room_no}','{$personal_home_no}','{$personal_village_name}','{$personal_mhu}','{$personal_soi}','{$personal_road}','{$personal_subdistrict}','{$personal_district}','{$personal_province}','{$personal_postal_code}','D','1',NOW())
sql;
        $result = $db->Execute($sql);
        
        if(!$result)
        {
            echo '<script>alert("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้งภายหลัง");top.window.location="../home.php";</script>';
        }
        else
        {
            $tutor_id = $db->Insert_ID();
            
            if(isset($_FILES['personal_photo']) AND $_FILES['personal_photo']['name']!='')
            {
                $handle = new Upload($_FILES['personal_photo']);
                
                $handle->allowed = array('image/*');
                
                if( $handle->uploaded )
                {
                    $handle->file_new_name_body = $tutor_id.'-profile';
                    $handle->Process($iniVars['Locations']['tl_job_img_folder']);
                    if($handle->processed)
                    {
                        $sql = 'UPDATE tutor SET tutor_image="'.$handle->file_dst_name.'" WHERE tutor_id='.$tutor_id;
                        $result = $db->Execute($sql);
                    }
                }
            }
?>
    <script>
        $(document).ready(function(){
            $("#tutor_id_for_frm2",top.document).val('<?php echo $tutor_id; ?>');
            $("#tutor_id_for_frm3",top.document).val('<?php echo $tutor_id; ?>');
            $("#jobs_group_1",top.document).hide('fade',1000,function(){
                $("#jobs_group_2",top.document).css('display','block');
            });
            
        });
    </script>
<?php
        }
        
        
    }
    else if($frm_no==2)
    {
        $tutor_id = $_POST['tutor_id_for_frm2'];
        
        $personal_degree_of_current_study = $_POST['personal_degree_of_current_study'];
        $personal_current_university = $_POST['personal_current_university'];
        $personal_current_faculty = $_POST['personal_current_faculty'];
        $personal_current_student_id = $_POST['personal_current_student_id'];
        $personal_current_academic_year = $_POST['personal_current_academic_year'];
        $personal_current_gpa = $_POST['personal_current_gpa'];
        
        if($personal_degree_of_current_study!='' OR $personal_current_university!='' OR $personal_current_faculty!='' OR $personal_current_student_id!='' OR $personal_current_academic_year!='' OR $personal_current_gpa!='')
        {
            $edu_status=1;
        }
        else
        {
            $edu_status=0;
        }
        
        $personal_current_faculty1 = $_POST['personal_primary_school'];
        $personal_current_student_id1 = $_POST['personal_primary_faculty'];
        $personal_current_academic_year1 = $_POST['personal_primary_student_id'];
        $personal_current_gpa1 = $_POST['personal_primary_gpa'];
        
        $personal_current_faculty2 = $_POST['personal_secondary_school'];
        $personal_current_student_id2 = $_POST['personal_secondary_faculty'];
        $personal_current_academic_year2 = $_POST['personal_secondary_student_id'];
        $personal_current_gpa2 = $_POST['personal_secondary_gpa'];
        
        $personal_current_faculty3 = $_POST['personal_high_school'];
        $personal_current_student_id3 = $_POST['personal_high_faculty'];
        $personal_current_academic_year3 = $_POST['personal_high_student_id'];
        $personal_current_gpa3 = $_POST['personal_high_gpa'];
        
        $personal_current_faculty4 = $_POST['personal_bachelor_school'];
        $personal_current_student_id4 = $_POST['personal_bachelor_faculty'];
        $personal_current_academic_year4 = $_POST['personal_bachelor_student_id'];
        $personal_current_gpa4 = $_POST['personal_bachelor_gpa'];
        
        $personal_current_faculty5 = $_POST['personal_master_school'];
        $personal_current_student_id5 = $_POST['personal_master_faculty'];
        $personal_current_academic_year5 = $_POST['personal_master_student_id'];
        $personal_current_gpa5 = $_POST['personal_master_gpa'];
        
        $personal_current_faculty6 = $_POST['personal_doctorate_school'];
        $personal_current_student_id6 = $_POST['personal_doctorate_faculty'];
        $personal_current_academic_year6 = $_POST['personal_doctorate_student_id'];
        $personal_current_gpa6 = $_POST['personal_doctorate_gpa'];
        
        $jobs_subjects_to_teach_subject = $_POST['jobs_subjects_to_teach_subject'];
        $jobs_subjects_to_teach_levels = $_POST['jobs_subjects_to_teach_levels'];
        $jobs_subjects_to_teach_areas = $_POST['jobs_subjects_to_teach_areas'];
        
        $sql = <<<sql
            UPDATE tutor SET edu_status='{$edu_status}',
            edu_current_level='{$personal_degree_of_current_study}',
            edu_current_university='{$personal_current_university}',
            edu_current_department='{$personal_current_faculty}',
            edu_current_student_id='{$personal_current_student_id}',
            edu_current_class='{$personal_current_academic_year}',
            edu_current_GPA='{$personal_current_gpa}',
            
            edu_pratom_school='{$personal_current_faculty1}',
            edu_pratom_major='{$personal_current_student_id1}',
            edu_pratom_student_id='{$personal_current_academic_year1}',
            edu_pratom_GPA='{$personal_current_gpa1}',
            
            edu_mo_tom_school='{$personal_current_faculty2}',
            edu_mo_tom_major='{$personal_current_student_id2}',
            edu_mo_tom_student_id='{$personal_current_academic_year2}',
            edu_mo_tom_GPA='{$personal_current_gpa2}',
            
            edu_mo_pay_school='{$personal_current_faculty3}',
            edu_mo_pay_major='{$personal_current_student_id3}',
            edu_mo_pay_student_id='{$personal_current_academic_year3}',
            edu_mo_pay_GPA='{$personal_current_gpa3}',
            
            edu_bachelor_university='{$personal_current_faculty4}',
            edu_bachelor_major='{$personal_current_student_id4}',
            edu_bachelor_student_id='{$personal_current_academic_year4}',
            edu_bachelor_GPA='{$personal_current_gpa4}',
            
            edu_master_university='{$personal_current_faculty5}',
            edu_master_major='{$personal_current_student_id5}',
            edu_master_student_id='{$personal_current_academic_year5}',
            edu_master_GPA='{$personal_current_gpa5}',
            
            edu_doctor_university='{$personal_current_faculty6}',
            edu_doctor_major='{$personal_current_student_id6}',
            edu_doctor_student_id='{$personal_current_academic_year6}',
            edu_doctor_GPA='{$personal_current_gpa6}',
            
            teach01_subject='{$jobs_subjects_to_teach_subject[0]}',
            teach01_class='{$jobs_subjects_to_teach_levels[0]}',
            
            teach02_subject='{$jobs_subjects_to_teach_subject[1]}',
            teach02_class='{$jobs_subjects_to_teach_levels[1]}',
            
            teach03_subject='{$jobs_subjects_to_teach_subject[2]}',
            teach03_class='{$jobs_subjects_to_teach_levels[2]}',
            
            teach04_subject='{$jobs_subjects_to_teach_subject[3]}',
            teach04_class='{$jobs_subjects_to_teach_levels[3]}',
            
            teach05_subject='{$jobs_subjects_to_teach_subject[4]}',
            teach05_class='{$jobs_subjects_to_teach_levels[4]}',
            
            teach06_subject='{$jobs_subjects_to_teach_subject[5]}',
            teach06_class='{$jobs_subjects_to_teach_levels[5]}',
            
            teach_area='{$jobs_subjects_to_teach_areas}' WHERE tutor_id={$tutor_id}
sql;
        $result = $db->Execute($sql);
        
        if(!$result)
        {
            echo '<script>alert("ไม่สามารถบันทึกข้อมูลได้ กรุณาลองใหม่อีกครั้ง");</script>';
        }
        else
        {
?>
        <script>
            $(document).ready(function(){
                $("#jobs_group_2",top.document).hide('fade',1000,function(){
                    $("#jobs_box_6",top.document).css('display','block');
                });
            });
        </script>
<?php
        }
        
    }
    else if($frm_no==3)
    {
        $tutor_id = $_POST['tutor_id_for_frm3'];
        
        $jobs_experiences_teaching_experiences = $_POST['jobs_experiences_teaching_experiences'];
        $jobs_experiences_positions_and_types = $_POST['jobs_experiences_positions_and_types'];
        $jobs_experiences_how_know = $_POST['jobs_experiences_how_know'];
        
        $sql = <<<sql
            UPDATE tutor SET hist_profile='{$jobs_experiences_teaching_experiences}',
            hist_related_work='{$jobs_experiences_positions_and_types}',
            known_from='{$jobs_experiences_how_know}' WHERE tutor_id={$tutor_id}
sql;
        $result = $db->Execute($sql);
        
        if(isset($_FILES['jobs_experiences_resume']) AND $_FILES['jobs_experiences_resume']['name']!='')
        {
            $handle = new Upload($_FILES['jobs_experiences_resume']);
            
            $handle->allowed = array('application/pdf','application/msword' ,'application/x-pdf','application/zip','application/rar');
            
            if( $handle->uploaded )
            {
                $handle->file_new_name_body = $tutor_id.'-resume';
                $handle->Process($iniVars['Locations']['tl_job_img_folder']);
                if($handle->processed)
                {
                    $sql = 'UPDATE tutor SET hist_resume_path="'.$handle->file_dst_name.'" WHERE tutor_id='.$tutor_id;
                    $result = $db->Execute($sql);
                }
            }
        }
?>
    <script>
            alert('ข้อมูลของท่านได้รับการบันทึกแล้ว กรุณารอการติดต่อกลับจากเรา');
            top.window.location="../home.php";
    </script>
<?php
        
    }

?>